#{include file="wxapp/head.html"}# 
<!-- page 容器 -->
<div id="customer_show_one" class="page"> 
  <!-- 标题栏 -->
  <header class="bar bar-nav"> <a href="#{$smarty.const.ACT}#/wxapp/WxCustomer/customer_show/" class="button button-link button-nav pull-left back"><span class="icon icon-left"></span>返回</a>
    <h1 class="title">客户详细</h1>
  </header>
  <!-- 工具栏 -->
	 <p><a data-popover=".popover-links" class="open-popover">Show Popover</a></p>
	<nav class="bar bar-tab">
	  <a href="#" class="tab-item open-popover active" data-popover=".popover-links" >
		<span class="iconfont icon icon-tianjiazijiedian"></span>
	  </a>
	</nav>  
  <!-- 这里是页面内容区 -->
  <div class="content infinite-scroll infinite-scroll-bottom" data-distance="50">
     <div class="list-block media-list customer-tabs-top">
      <ul>
        <li><a href="#{$smarty.const.ACT}#/wxapp/WxCustomer/customer_show_one_info/" class="item-link item-content">
          <div class="item-inner">
            <div class="item-title-row">
              <div class="item-title"><i class="icon icon-f7"></i> #{$one.name}#</div>
              <div class="item-after">#{$one.level_name}#</div>
            </div>
            <div class="item-text">
					负责人: #{$one.linkman}#
					<div class="item-title-row">
						<div class="item-title">联系电话：#{$one.mobile}#</div>
						<div class="item-after"><i class="icon icon-phone"></i></div>
					</div>
			    </div>
          </div>
           </a>
         </li>      
      </ul>
    </div>   
	  
    <div class="buttons-tab customer-tabs-tit">
      <a href="#tab1" class="tab-link active button">跟踪记录</a>
      <a href="#tab2" class="tab-link button">销售机会</a>
      <a href="#tab3" class="tab-link button">联系人</a>
      <a href="#tab4" class="tab-link button">合同</a>
      <a href="#tab5" class="tab-link button">订单</a>
    </div>

    <div class="tabs customer-tabs-con pull-to-refresh-container">
      <div id="tab1" class="tab active infinite-scroll" data-distance="100">
		  <span class="data" data-currentPage="" data-totalCount="" data-numPerPage=""></span>
			<div class="list-block media-list">
			  <ul class="list-container"> 					  
			  </ul>
			</div>			
        <div class="infinite-scroll-preloader">
          <div class="preloader">
          </div>
        </div>
		 
      </div>
      <div id="tab2" class="tab infinite-scroll">
		  <span class="data" data-currentPage="" data-totalCount="" data-numPerPage=""></span>
        <div class="list-block media-list">
			  <ul class="list-container"> 					  
			  </ul>
			</div>	
		  
        <div class="infinite-scroll-preloader">
          <div class="preloader">
          </div>
        </div>
      </div>
      <div id="tab3" class="tab infinite-scroll">
		  <span class="data" data-currentPage="" data-totalCount="" data-numPerPage=""></span>
        <div class="list-block media-list">
			  <ul class="list-container"> 					  
			  </ul>
			</div>
        <div class="infinite-scroll-preloader">
          <div class="preloader">
          </div>
        </div>
      </div>
      <div id="tab4" class="tab infinite-scroll">
		  <span class="data" data-currentPage="" data-totalCount="" data-numPerPage=""></span>
        <div class="list-block media-list">
			  <ul class="list-container"> 					  
			  </ul>
			</div>
        <div class="infinite-scroll-preloader">
          <div class="preloader">
          </div>
        </div>
      </div>
      <div id="tab5" class="tab infinite-scroll">
		  <span class="data" data-currentPage="" data-totalCount="" data-numPerPage=""></span>
        <div class="list-block media-list">
			  <ul class="list-container"> 					  
			  </ul>
			</div>
        <div class="infinite-scroll-preloader">
          <div class="preloader">
          </div>
        </div>
      </div>
    </div> 
  </div>
</div>
<!-- page 容器结束 --> 
<div class="popover popover-links">
  <div class="popover-angle"></div>
  <div class="popover-inner">
    <div class="list-block">
      <ul>
        <li><a href="#{$smarty.const.ACT}#/wxapp/WxCstTrace/cst_trace_add/" class="list-button item-link" external>记录</a></li>
        <li><a href="#{$smarty.const.ACT}#/wxapp/WxCstChance/cst_chance_add/" class="list-button item-link" external>机会</a></li>
        <li><a href="#{$smarty.const.ACT}#/wxapp/WxCstLinkman/cst_linkman_add/" class="list-button item-link" external>联系人</a></li>
        <li><a href="#{$smarty.const.ACT}#/wxapp/WxCstContract/sal_contract_add/" class="list-button item-link" external>合同</a></li>
        <li><a href="#{$smarty.const.ACT}#/wxapp/WxCstOrder/sal_order_add/" class="list-button item-link" external>订单</a></li>
      </ul>
    </div>
  </div>
</div>
#{include file="wxapp/foot.html"}#
<script>
 $(document).ready(function(){//关键
	var ACT='#{$smarty.const.ACT}#';
	// 加载flag
	var loading = false;

	function addItems(pageNum, numPerPage,urltype) {
		var apiurl="";
		if(urltype=="customer"){
			apiurl=ACT+'/wxapp/WxCustomer/customer/';	
		}else if(urltype=="tab1"){
			apiurl=ACT+'/wxapp/WxCstTrace/cst_trace/cusID/#{$one.id}#/';	
		}else if(urltype=="tab2"){
			apiurl=ACT+'/wxapp/WxCstChance/cst_chance/cusID/#{$one.id}#/';	
		}else if(urltype=="tab3"){
			apiurl=ACT+'/wxapp/WxCstLinkman/cst_linkman/cusID/#{$one.id}#/';	
		}else if(urltype=="tab4"){
			apiurl=ACT+'/wxapp/WxSalContract/sal_contract/cusID/#{$one.id}#/';	
		}else if(urltype=="tab5"){
			apiurl=ACT+'/wxapp/WxSalOrder/sal_order/cusID/#{$one.id}#/';	
		}
		$.ajax({
		  type: "POST",//方法类型
		  dataType: "json",//预期服务器返回的数据类型
		  data: {pageNum: pageNum, numPerPage: numPerPage},  //异步返回给data
		  url: apiurl,  //接口地址
		  timeout: 300,
		  success: function (data) {
				  console.log(data);
				  var datalist=data.list;
				  var html = '';
				  for(var i=0;i<datalist.length;i++){
					  if(urltype=="tab1"){
							 html += '<li> <a href='+ACT+'"/wxapp/WxCustomer/customer_show_one/" class="item-link item-content">';
							 html += ' <div class="item-inner">';
							 html += '   <div class="item-title-row">';
							 html += '     <div class="item-title">'+datalist[i].create_user_name+'</div>';
							 html += '     <div class="item-after">'+datalist[i].salestage_name+'</div>';
							 html += '   </div>';
							 html += '   <div class="item-subtitle">'+datalist[i].bdt+'('+datalist[i].salemode_name+')</div>';
							 html += '   <div class="item-text">'+datalist[i].title+'</div>';
						   	html += '   <div class="item-subtitle">下次联系时间：'+datalist[i].bdt+'</div>';
							 html += ' </div>';
							 html += ' </a> ';
							 html += '</li>';
					  }else if(urltype=="tab2"){
							 html += '<li> <a href='+ACT+'"/wxapp/WxCustomer/customer_show_one/" class="item-link item-content">';
							 html += ' <div class="item-inner">';
							 html += '   <div class="item-title-row">';
							 html += '     <div class="item-title">'+datalist[i].title+'</div>';
							 html += '     <div class="item-after">'+datalist[i].salestage_name+'('+datalist[i].chance+'%)</div>';
							 html += '   </div>';
							 html += '   <div class="item-subtitle">';
							 html += '   	<div class="item-title-row">';
							 html += '     	 <div class="item-title">预计签单时间：'+datalist[i].billdt+'</div>';
							 html += '     	 <div class="item-after">预计金额：'+datalist[i].money+'</div>';
							 html += '   	</div>';						  
						  	 html += '   </div>';
							 html += ' </div>';
							 html += ' </a> ';
							 html += '</li>';
					  }else if(urltype=="tab3"){
							 html += '<li> <a href='+ACT+'"/wxapp/WxCustomer/customer_show_one/" class="item-link item-content">';
							 html += ' <div class="item-inner">';
							 html += '   <div class="item-title-row">';
							 html += '     <div class="item-title">'+datalist[i].name+'</div>';
							 html += '     <div class="item-after">'+datalist[i].postion+'</div>';
							 html += '   </div>';
							 html += '   <div class="item-subtitle">手机：'+datalist[i].mobile+'</div>';
							 html += ' </div>';
							 html += ' </a> ';
							 html += '</li>';
					  }else if(urltype=="tab4"){
							 html += '<li> <a href='+ACT+'"/wxapp/WxCustomer/customer_show_one/" class="item-link item-content">';
							 html += ' <div class="item-inner">';
							 html += '   <div class="item-title-row">';
							 html += '     <div class="item-title">'+datalist[i].title+'</div>';
							 html += '     <div class="item-after">'+datalist[i].status_name+'</div>';
							 html += '   </div>';
							 html += '   <div class="item-subtitle">';
							 html += '   	<div class="item-title-row">';
							 html += '     	 <div class="item-title">合同金额：'+datalist[i].money+'</div>';
							 html += '     	 <div class="item-after">已收金额：'+datalist[i].back_money+'</div>';
							 html += '   	</div>';						  
						  	 html += '   </div>';
							 html += '   <div class="item-text">';
							 html += '   	<div class="item-title-row">';
							 html += '     	 <div class="item-title">开始日期：'+datalist[i].bdt+'</div>';
							 html += '     	 <div class="item-after">结束日期：'+datalist[i].edt+'</div>';
							 html += '   	</div>';						  
						  	 html += '   </div>';
							 html += ' </div>';
							 html += ' </a> ';
							 html += '</li>';
					  }else if(urltype=="tab5"){
							 html += '<li> <a href='+ACT+'"/wxapp/WxCustomer/customer_show_one/" class="item-link item-content">';
							 html += ' <div class="item-inner">';
							 html += '   <div class="item-title-row">';
							 html += '     <div class="item-title">'+datalist[i].title+'</div>';
							 html += '     <div class="item-after">'+datalist[i].status_name+'</div>';
							 html += '   </div>';
							 html += '   <div class="item-subtitle">';
							 html += '   	<div class="item-title-row">';
							 html += '     	 <div class="item-title">订单金额：'+datalist[i].money+'</div>';
							 html += '     	 <div class="item-title">已收金额：'+datalist[i].back_money+'</div>';
							 html += '   	</div>';						  
						  	 html += '   </div>';
							 html += '   <div class="item-text">';
							 html += '   	<div class="item-title-row">';
							 html += '     	 <div class="item-title">下单日期：'+datalist[i].bdt+'</div>';
							 html += '     	 <div class="item-title">发货日期：'+datalist[i].edt+'</div>';
							 html += '   	</div>';						  
						  	 html += '   </div>';
							 html += ' </div>';
							 html += ' </a> ';
							 html += '</li>';
					  }
				   }
					// 添加新条目
				   $('#'+urltype+' .list-container').append(html);
				   $('#'+urltype+' .data').attr('data-currentPage',parseInt(data.currentPage));
				   $('#'+urltype+' .data').attr('data-totalCount',parseInt(data.totalCount));
				   $('#'+urltype+' .data').attr('data-numPerPage',parseInt(data.numPerPage));
			  		
			  		if(parseInt(data.totalCount)<=10){
						// 加载完毕，则注销无限加载事件，以防不必要的加载
					  $.detachInfiniteScroll($('#'+urltype+' .infinite-scroll'));
					  // 删除加载提示符
					  $('#'+urltype+' .infinite-scroll-preloader').remove();
					  return;						
					}
			  
					return html;

		  }
		});
	}
  //预先加载第一页内容
  addItems(1, 10,'tab1');
  addItems(1, 10,'tab2');
  addItems(1, 10,'tab3');
  addItems(1, 10,'tab4');
  addItems(1, 10,'tab5');
  // 注册'infinite'事件处理函数
  $(document).on('infinite', '.infinite-scroll',function() {
		if($("#tab1").hasClass("active")){
			// 如果正在加载，则退出
			if (loading) return;
			 // 设置flag
			 loading = true;
			 // 模拟1s的加载过程
			 setTimeout(function() {
				  // 重置加载flag
				loading = false;
				var currentPage	 = Number( $('#tab1 .data').attr('data-currentPage') );
				var totalCount	 = Number( $('#tab1 .data').attr('data-totalCount') );
				var numPerPage	 = Number( $('#tab1 .data').attr('data-numPerPage') );
				var maxPage 	 = Math.ceil(totalCount/numPerPage);
				if (currentPage >= maxPage) {
				  // 加载完毕，则注销无限加载事件，以防不必要的加载
				  $.detachInfiniteScroll($('#tab1 .infinite-scroll'));
				  // 删除加载提示符
				  $('#tab1 .infinite-scroll-preloader').remove();
				  return;
				}
				// 添加新条目
				addItems(currentPage+1, numPerPage,'tab1');

			  }, 1000);
		}else if($("#tab2").hasClass("active")){  
			// 如果正在加载，则退出
			if (loading) return;
			 // 设置flag
			 loading = true;
			 // 模拟1s的加载过程
			 setTimeout(function() {
				  // 重置加载flag
				loading = false;
				var currentPage	 = Number( $('#tab2 .data').attr('data-currentPage') );
				var totalCount	 = Number( $('#tab2 .data').attr('data-totalCount') );
				var numPerPage	 = Number( $('#tab2 .data').attr('data-numPerPage') );
				var maxPage = Math.ceil(totalCount/numPerPage);
				if (currentPage >= maxPage) {
				  // 加载完毕，则注销无限加载事件，以防不必要的加载
				  $.detachInfiniteScroll($('#tab2 .infinite-scroll'));
				  // 删除加载提示符
				  $('#tab2 .infinite-scroll-preloader').remove();
				  return;
				}
				// 添加新条目
				 addItems(currentPage+1, numPerPage,'tab2');

			  }, 1000);			
	   }else if($("#tab3").hasClass("active")){  
			// 如果正在加载，则退出
			if (loading) return;
			 // 设置flag
			 loading = true;
			 // 模拟1s的加载过程
			 setTimeout(function() {
				  // 重置加载flag
				loading = false;
				var currentPage	 = Number( $('#tab3 .data').attr('data-currentPage') );
				var totalCount	 = Number( $('#tab3 .data').attr('data-totalCount') );
				var numPerPage	 = Number( $('#tab3 .data').attr('data-numPerPage') );
				var maxPage = Math.ceil(totalCount/numPerPage);
				if (currentPage >= maxPage) {
				  // 加载完毕，则注销无限加载事件，以防不必要的加载
				  $.detachInfiniteScroll($('#tab3 .infinite-scroll'));
				  // 删除加载提示符
				  $('#tab3 .infinite-scroll-preloader').remove();
				  return;
				}
				// 添加新条目
				 addItems(currentPage+1, numPerPage,'tab2');
				 
			  }, 1000);			
	   }else if($("#tab4").hasClass("active")){  
			// 如果正在加载，则退出
			if (loading) return;
			 // 设置flag
			 loading = true;
			 // 模拟1s的加载过程
			 setTimeout(function() {
				  // 重置加载flag
				loading = false;
				var currentPage	 = Number( $('#tab4 .data').attr('data-currentPage') );
				var totalCount	 = Number( $('#tab4 .data').attr('data-totalCount') );
				var numPerPage	 = Number( $('#tab4 .data').attr('data-numPerPage') );
				var maxPage = Math.ceil(totalCount/numPerPage);
				if (currentPage >= maxPage) {
				  // 加载完毕，则注销无限加载事件，以防不必要的加载
				  $.detachInfiniteScroll($('#tab4 .infinite-scroll'));
				  // 删除加载提示符
				  $('#tab4 .infinite-scroll-preloader').remove();
				  return;
				}
				// 添加新条目
				 addItems(currentPage+1, numPerPage,'tab2');

			  }, 1000);			
	   }else if($("#tab5").hasClass("active")){  
			// 如果正在加载，则退出
			if (loading) return;
			 // 设置flag
			 loading = true;
			 // 模拟1s的加载过程
			 setTimeout(function() {
				  // 重置加载flag
				loading = false;
				var currentPage	 = Number( $('#tab5 .data').attr('data-currentPage') );
				var totalCount	 = Number( $('#tab5 .data').attr('data-totalCount') );
				var numPerPage	 = Number( $('#tab5 .data').attr('data-numPerPage') );
				var maxPage = Math.ceil(totalCount/numPerPage);
				if (currentPage >= maxPage) {
				  // 加载完毕，则注销无限加载事件，以防不必要的加载
				  $.detachInfiniteScroll($('#tab5 .infinite-scroll'));
				  // 删除加载提示符
				  $('#tab5 .infinite-scroll-preloader').remove();
				  return;
				}
				// 添加新条目
				 addItems(currentPage+1, numPerPage,'tab2');

			  }, 1000);			
	   }

  });//end infinite 
	
 $.init();//关键
 });
</script>